package com.yishe.controller.tech;

import com.yishe.biz.mysql.YsCaseInfoBiz;
import com.yishe.biz.mysql.YsStaffBiz;
import com.yishe.biz.mysql.YsStaffCaseBiz;
import com.yishe.biz.tech.TechBiz;
import com.yishe.biz.tech.YsCaseTypeInfoBiz;
import com.yishe.config.ObjectRestResponse;
import com.yishe.entites.mysql.CaseTypeMaintain;
import com.yishe.entites.mysql.YsStaff;
import com.yishe.entites.vo.YsStaffCaseDetailVo;
import com.yishe.entites.vo.YsStaffCaseVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author : chusifeng
 * @version :1.0
 * @date :Create in 2021/4/8 16:23
 * @description: 老師模塊
 * @package com.yishe.controller
 * @className TechController
 */
@RestController
@Slf4j
@RequestMapping("tech")
public class TechController {

    @Resource
    private TechBiz techBiz;
    @Resource
    private YsStaffBiz ysStaffBiz;
    @Resource
    private YsCaseInfoBiz ysCaseInfoBiz;
    @Resource
    private YsStaffCaseBiz ysStaffCaseBiz;
    @Resource
    private YsCaseTypeInfoBiz ysCaseTypeInfoBiz;


    /**
     * 获取约课课程信息
     * @param account
     * @return
     */
    @GetMapping(value = "getCaseListDetail")
    public ObjectRestResponse getCaseListDetail(String account) {
        log.info("教師登錄"+ account);
        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            List<YsStaffCaseDetailVo> caseListDetail = techBiz.getCaseListDetail(account);
            restResponse.setData(caseListDetail);
        } catch (Exception e) {
            log.error("查询名下课程信息出错！"+e);
            restResponse.setErrorMsg(e.getMessage());
        }
        return restResponse;
    }
    /**
     * 获取约课课程信息
     * @param account
     * @return
     */
    @GetMapping(value = "getCaseList")
    public ObjectRestResponse getCaseList(String account) {
        log.info("教師登錄"+ account);
        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            List<Map<String, Object>> caseListDetail = techBiz.getCaseList(account);
            restResponse.setData(caseListDetail);
        } catch (Exception e) {
            log.error("查询名下课程信息出错！"+e);
            restResponse.setErrorMsg(e.getMessage());
        }
        return restResponse;
    }
    /**
     * 获取课程信息
     * @param params
     * @return
     */
    @PostMapping(value = "getCaseObject")
    public ObjectRestResponse getCaseObject(@RequestBody Map<String,String> params) {
        log.info("獲取課程信息入參："+ params);
        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            YsStaffCaseVo caseDetail = techBiz.getCaseObject(params);
            restResponse.setData(caseDetail);
        } catch (Exception e) {
            log.error("课程信息查询出错！"+e);
            restResponse.setErrorMsg(e.getMessage());
        }
        return restResponse;
    }
    /**
     * 获取所有员工
     * @return
     */
    @GetMapping(value = "getAllYsUsers")
    public ObjectRestResponse getAllYsUsers() {

        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            List<YsStaff> caseListDetail = ysStaffBiz.getAllList();
            restResponse.setData(caseListDetail);
        } catch (Exception e) {
            log.error("获取所有员工信息出错！"+e);
            restResponse.setErrorMsg(e.getMessage());
        }
        return restResponse;
    }
    /**
     * 根据课程编号删除系统课程，删除时判断是否已分配课程了
     * @return
     */
    @PostMapping(value = "deleteCase")
    public ObjectRestResponse deleteCase(@RequestBody Map<String,String> param) {

        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            String msg = ysCaseInfoBiz.deleteCase(param);
            if (StringUtils.isBlank(msg)){
                restResponse.setSuccessMsg("删除成功");
            } else {
                restResponse.setErrorMsg(msg);
            }
        } catch (Exception e) {
            log.error("删除课程失败！"+e);
            restResponse.setErrorMsg("删除课程失败！");
        }
        return restResponse;
    }
    /**
     * 编辑系统课程
     * @return
     */
    @PostMapping(value = "saveCaseEdit")
    public ObjectRestResponse saveCaseEdit(@RequestBody Map<String,Object> param) {

        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
             ysCaseInfoBiz.saveCaseEdit(param);
             restResponse.setSuccessMsg("修改成功");
        } catch (Exception e) {
            log.error("修改课程失败！"+e);
            restResponse.setErrorMsg("修改课程失败！");
        }
        return restResponse;
    }
    /**
     * 编辑系统课程
     * @return
     */
    @PostMapping(value = "saveCase")
    public ObjectRestResponse saveCase(@RequestBody Map<String,Object> param) {

        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            ysCaseInfoBiz.saveCase(param);
            restResponse.setSuccessMsg("新增成功");
        } catch (Exception e) {
            log.error("新增课程失败！"+e);
            restResponse.setErrorMsg("新增课程失败！");
        }
        return restResponse;
    }/**
     * 编辑系统课程
     * @return
     */
    @PostMapping(value = "saveCaseType")
    public ObjectRestResponse saveCaseType(@RequestBody CaseTypeMaintain caseTypeMaintain) {

        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            ysCaseTypeInfoBiz.saveCaseType(caseTypeMaintain);
            restResponse.setSuccessMsg("新增成功");
        } catch (Exception e) {
            log.error("新增课程失败！"+e);
            restResponse.setErrorMsg("新增课程失败！");
        }
        return restResponse;
    }
    /**
     * 编辑系统课程
     * @return
     */
    @GetMapping(value = "getCaseTyeList")
    public ObjectRestResponse getCaseTyeList() {

        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            restResponse.setData(ysCaseTypeInfoBiz.getCaseTyeList());
            restResponse.setSuccessMsg("获取所有类型");
        } catch (Exception e) {
            log.error("获取课程类型失败！"+e);
            restResponse.setErrorMsg("获取课程类型失败！");
        }
        return restResponse;
    }
    /**
     * 根据课程编号删除系统课程，删除时判断是否已分配课程了
     * @return
     */
    @PostMapping(value = "distributeToStaff")
    public ObjectRestResponse distributeToStaff(@RequestBody Map<String,String> param) {

        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            String msg = ysStaffCaseBiz.distributeToStaff(param);
            if (StringUtils.isBlank(msg)){
                restResponse.setSuccessMsg("分配成功");
            } else {
                restResponse.setErrorMsg(msg);
            }
        } catch (Exception e) {
            log.error("分配课程失败！"+e);
            restResponse.setErrorMsg("分配课程失败！");
        }
        return restResponse;
    }

}
